package com.rd.student.dashuju.zhengruixian.test0726;

public class TestTicket implements Runnable{
    int ticketsNum=100;
    @Override
public void run(){
        while (true){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (ticketsNum<=0){
                System.out.println("票卖光了");
                return;
            }
            System.out.println(Thread.currentThread().getName()+"出票"
                     +ticketsNum );
            ticketsNum--;
        }
    }

    public static void main(String[] args) {
        TestTicket ticket=new TestTicket();
        Thread t1=new Thread(ticket);
        Thread t2=new Thread(ticket);
        Thread t3=new Thread(ticket);
        t1.start();
        t2.start();
        t3.start();
    }
}
